//
//  SellingCell.m
//  WestAir
//
//  Created by s on 16/9/27.
//  Copyright © 2016年 Henry. All rights reserved.
//

#import "SellingCell.h"


@implementation SellingCell{


    UITextField  *textModifyPrice;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.TextViewContent.delegate=self;
    
    VIEW_CORNER(_viewBackGround, 4.0);
    [[NSNotificationCenter     defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextFieldTextDidChangeNotification object:self.TextViewContent];
    [[NSNotificationCenter     defaultCenter] addObserver:self selector:@selector(lableNumDidChange:) name:UITextFieldTextDidChangeNotification object:self.lableNum];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (IBAction)btnModifiedPrice:(id)sender {
    
    
    [CMCCIOTTipsCenter   showAlertTextFieldTitle:@"修改价格" message:@"" andTFOne:^(UITextField * _Nullable textField) {
        
        UIView  *leftView=[[UIView alloc]  initWithFrame:CGRectMake(0, 0, 10, 10)]          ;
        
        textField.leftView=leftView;
        textField.leftViewMode=UITextFieldViewModeAlways;
        textField.keyboardType=UIKeyboardTypeDecimalPad; ;
        [[NSNotificationCenter  defaultCenter]  addObserver:self selector:@selector(textFieldChange:) name:UITextFieldTextDidChangeNotification object:textField];
        textModifyPrice=textField;
        textModifyPrice.text=[NSString stringWithFormat:@"%.1f", self.modle.FPrice];
        
        ;
    } andTFTwo:nil cancelTitle:@"取消" cancelBlock:^(CMCCIOTIGAlertActionCustomer * _Nullable action) {
        
        
        ;
    } quireTitle:@"确定" quireBlock:^(CMCCIOTIGAlertActionCustomer * _Nullable action) {
        
        if (textModifyPrice.text.length) {
            self.lablePrice.text=[NSString stringWithFormat:@"%.1f", [textModifyPrice.text floatValue]];
            CGSize  lableSize = [CMCCIOTIGUnity  getSize:self.lablePrice.text andSize:CGSizeMake(MAXFLOAT, self.lablePrice.heightV)  and:self.lablePrice.font];
            self.lablePriceWidth.constant=lableSize.width+5;
            
            self.modle.FPrice=[self.lablePrice.text floatValue];
            [self.delegate  modifyPrice:self.currentIndex   and:self.modle];
        }
      

    }  ];
    
    
}
- (IBAction)btnSub:(id)sender {
    
    if ([self.lableNum.text  integerValue]>0) {
        
        self.lableNum.text=[NSString stringWithFormat:@"%ld",[self.lableNum.text  integerValue]-1];
        self.modle.FQty=[self.lableNum.text  integerValue];
        [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
    
    }

}
- (IBAction)btnAdd:(id)sender {
    
     self.lableNum.text=[NSString stringWithFormat:@"%ld",[self.lableNum.text  integerValue]+1];
     self.modle.FQty=[self.lableNum.text  integerValue];
     [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
    
}


-(void)textFieldChange:(NSNotification  *)notification{
    
    UITextField  *textField=[notification   object ];
    if (textField.text.length>6) {
        textField.text=[textField.text substringToIndex:6];
    }
    
    
    
}


#pragma mark textField  delegate


-(void)textDidChange:(NSNotification *)object{
    
    UITextField  *text= [object  object];
    
    self.modle.FRemark=text.text ;
    [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
    
}
-(void)lableNumDidChange:(NSNotification *)object{
    
    UITextField  *text= [object  object];
    self.modle.FQty=[text.text  integerValue];
    [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
    
}



- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    [self.delegate  becomeEditing:self.currentIndex];
    return YES;
}

@end


@implementation SellingCellZiTi{
    
    
    UITextField  *textModifyPrice;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    VIEW_CORNER(_viewBackGround, 4.0);
    self.TextViewContent.delegate=self;
    
    [[NSNotificationCenter     defaultCenter] addObserver:self selector:@selector(textDidChange:) name:UITextFieldTextDidChangeNotification object:self.TextViewContent];
    
     [[NSNotificationCenter     defaultCenter] addObserver:self selector:@selector(lableNumDidChange:) name:UITextFieldTextDidChangeNotification object:self.lableNum];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}

- (IBAction)btnSub:(id)sender {
    
    if ([self.lableNum.text  integerValue]>0) {
        
        self.lableNum.text=[NSString stringWithFormat:@"%ld",[self.lableNum.text  integerValue]-1];
        self.modle.FQty=[self.lableNum.text  integerValue];
        [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
        
    }
    
}
- (IBAction)btnAdd:(id)sender {
    
    self.lableNum.text=[NSString stringWithFormat:@"%ld",[self.lableNum.text  integerValue]+1];
    self.modle.FQty=[self.lableNum.text  integerValue];
    [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
    
}


-(void)textFieldChange:(NSNotification  *)notification{
    
    UITextField  *textField=[notification   object ];
    if (textField.text.length>6) {
        textField.text=[textField.text substringToIndex:6];
    }
    
}


#pragma mark textField  delegate

-(void)lableNumDidChange:(NSNotification *)object{
    
    UITextField  *text= [object  object];
    self.modle.FQty=[text.text  integerValue];
    [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
    
}


-(void)textDidChange:(NSNotification *)object{
    
    UITextField  *text= [object  object];
    
    self.modle.FRemark=text.text ;
    [self.delegate  modifyNumber:self.currentIndex  and:self.modle];
    
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    [self.delegate  becomeEditing:self.currentIndex];
    return YES;
}

@end
